package org.leiyang.common.proxy;

import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactivefeign.client.ReactiveHttpClient;
import reactivefeign.client.ReactiveHttpRequest;
import reactivefeign.client.ReactiveHttpResponse;
import reactivefeign.webclient.client.WebReactiveHttpClient;
import reactor.core.publisher.Mono;

public class WebReactiveHttpClientWrapper<P extends Publisher<?>> implements ReactiveHttpClient<P> {
    private static final Logger log = LoggerFactory.getLogger(WebReactiveHttpClientWrapper.class);
    private final WebReactiveHttpClient<P> reactiveHttpClient;

    public WebReactiveHttpClientWrapper(WebReactiveHttpClient<P> reactiveHttpClient) {
        this.reactiveHttpClient = reactiveHttpClient;
    }


    @Override
    public Mono<ReactiveHttpResponse<P>> executeRequest(ReactiveHttpRequest request) {
        if(request.headers().containsKey("yanglei")) {
            log.info("开始执行用户自定义的分支操作.");
            return Mono.empty();
        }

        return reactiveHttpClient.executeRequest(request);
    }
}
